//
//  LxHeader.m
//  MedicalClient
//
//  Created by H on 2018/4/13.
//  Copyright © 2018年 com.YouCanSee.xiaohan. All rights reserved.
//

#import "LxHeader.h"
API_AVAILABLE(ios(10.0))
@interface LxHeader()
@property (nonatomic,strong) UIImpactFeedbackGenerator*feedbackGenerator;
@end
@implementation LxHeader

- (void)prepare
{
    [super prepare];
//    //创建UIImageView
//    //根据拖拽的情况自动切换透明度
//    self.automaticallyChangeAlpha = YES;
//    //隐藏时间
//    self.lastUpdatedTimeLabel.hidden = YES;
//
////    MJRefreshStateIdle = 1,
////    /** 松开就可以进行刷新的状态 */
////    MJRefreshStatePulling,
////    /** 正在刷新中的状态 */
////    MJRefreshStateRefreshing,
//    [self setTitle:@"下拉刷新" forState:MJRefreshStateIdle];
//    [self setTitle:@"松开刷新" forState:MJRefreshStatePulling];
//    [self setTitle:@"正在刷新" forState:MJRefreshStateRefreshing];
    // 设置普通状态的动画图片
    self.lastUpdatedTimeLabel.hidden = YES;
    // 隐藏状态
    self.stateLabel.hidden = YES;
    NSMutableArray *idleImages = [NSMutableArray array];
    for (NSUInteger i = 0; i<=18; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"1_000%02ld", i]];
        [idleImages addObject:image];
    }
    [self setImages:idleImages forState:MJRefreshStateIdle];
    
    // 设置即将刷新状态的动画图片（一松开就会刷新的状态）
    NSMutableArray *refreshingImages = [NSMutableArray array];
    for (NSInteger i = 0; i<=18; i++) {
        if (i==0||i==3 || i == 8 || i==13 || i==18) {
            DLog(@"%@",[NSString stringWithFormat:@"1_000%02ld", i]);
            UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"1_000%02ld", i]];
            [refreshingImages addObject:image];
        }
    }
    [self setImages:refreshingImages forState:MJRefreshStatePulling];
    
    // 设置正在刷新状态的动画图片
    [self setImages:refreshingImages forState:MJRefreshStateRefreshing];
    
    if (@available(iOS 10.0, *)) {
        self.feedbackGenerator = [[UIImpactFeedbackGenerator alloc]initWithStyle:UIImpactFeedbackStyleLight];
        [self.feedbackGenerator prepare];
    } else {
        // Fallback on earlier versions
    }
}
#pragma mark 监听控件的刷新状态
- (void)setState:(MJRefreshState)state
{
    MJRefreshCheckState;
    
    switch (state) {
            case MJRefreshStateIdle:break;
            case MJRefreshStatePulling:{
                    if (@available(iOS 10.0, *)) {
                        [self.feedbackGenerator impactOccurred];
                    }
            }
            break;
            case MJRefreshStateRefreshing:
        default:
            break;
    }
}

@end
